package com.letv.thrift;

import java.util.ArrayList;
import java.util.List;

import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFastFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;

import serving.GenericDetailRequest;
import serving.GenericDetailServing;

import com.alibaba.fastjson.JSON;
import com.letv.mms.cache.factory.CacheFactory;
import com.letv.so.bean.AlbumBean;

public class ThriftClientTest {
    public static class CompactTest{
        public static void main(String...strings) {
            try{
//                TTransport transport = new TFastFramedTransport(new TSocket("localhost", 9099, 200000));
//                TTransport transport = new TFastFramedTransport(new TSocket("10.154.156.157", 9099, 200000));
                TTransport transport = new TFastFramedTransport(new TSocket("107.155.53.179", 9099, 200000));
                TProtocol protocol = new TCompactProtocol(transport);
                GenericDetailServing.Client client = new GenericDetailServing.Client(protocol);
                GenericDetailRequest request = new GenericDetailRequest();
                List<String>  ids = new ArrayList<String>();
//                ids.add("211_793");
//                ids.add("211_794");
//                ids.add("211_-2957839104857446542");
                ids.add("211_-1000993000859343864");
                request.setVideo_list_start_idx((short) 0);
                request.setVideo_list_num((short) 5);
                request.setIds(ids);
                transport.open();
                for (int i=0;i<1;i++) {
                    long crrent = System.currentTimeMillis();
                    System.out.println(client.GetDetailInfo(request));
                    System.out.println("use time:"+(System.currentTimeMillis() - crrent));
                }
                transport.close();
            } catch (TTransportException e) {  
                e.printStackTrace();  
            } catch (TException x) {  
                x.printStackTrace();  
            }
        }
    }
    
    public static class BinaryTest{
        public static void main(String...strings) {
            try{
//                TTransport transport = new TFastFramedTransport(new TSocket("10.154.156.157", 9090, 200000));
                TTransport transport = new TFastFramedTransport(new TSocket("107.155.53.179", 9090, 200000));
                TProtocol protocol = new TBinaryProtocol(transport,true,true);
                GenericDetailServing.Client client = new GenericDetailServing.Client(protocol);
                GenericDetailRequest request = new GenericDetailRequest();
                List<String>  ids = new ArrayList<String>();
//                ids.add("211_3478634573240433216");
//                ids.add("211_3478634573240433216");
//                ids.add("205_317239");
//                ids.add("211_-5162247408418804273");
                ids.add("211_8664088304053823434");
//                ids.add("205_356954");
                
                request.setVideo_list_start_idx((short) 0);
                request.setVideo_list_num((short) 1000);
                request.setIds(ids);
                transport.open();
                for (int i=0;i<1;i++) {
                    long crrent = System.currentTimeMillis();
                    System.out.println(client.GetDetailInfo(request));
                    System.out.println("use time:"+(System.currentTimeMillis() - crrent));
                }
                transport.close();
            } catch (TTransportException e) {  
                e.printStackTrace();  
            } catch (TException x) {  
                x.printStackTrace();  
            }
        }
    }
}
